/*
 * RemoteTableModel.java
 * 
 * Written by Joseph Bowbeer and released to the public domain,
 * as explained at http://creativecommons.org/licenses/publicdomain
 */

package jozart.remotetable;

import java.rmi.Remote;
import java.rmi.RemoteException;

/**
 * Specifies the methods the RemoteTable component will use to interrogate a
 * remote tabular data source.
 * 
 * @author Joseph Bowbeer
 * @version 1.0
 * @see javax.swing.table.TableModel
 */
public interface RemoteTableModel extends Remote {

    /**
     * Returns the number of records managed by the data source object.
     * 
     * @return the number of rows in the model
     * @throws RemoteException
     */
    int getRowCount() throws RemoteException;

    /**
     * Returns the number of columns managed by the data source object.
     * 
     * @return the number of columns in the model
     * @throws RemoteException
     */
    int getColumnCount() throws RemoteException;

    /**
     * Returns the name of the column at <tt>columnIndex</tt>.
     * 
     * @param columnIndex the index of column
     * @return the name of the column
     * @throws RemoteException
     */
    String getColumnName(int columnIndex) throws RemoteException;

    /**
     * Returns the lowest common denominator Class in the column.
     * 
     * @return the common ancestor class of the object values in the model
     * @throws RemoteException
     */
    Class<?> getColumnClass(int columnIndex) throws RemoteException;

    /**
     * Returns true if the cell at <tt>rowIndex</tt> and
     * <tt>columnIndex</tt> is editable.
     * 
     * @param rowIndex the row whose value is to be looked up
     * @param columnIndex the column whose value is to be looked up
     * @return true if the cell is editable
     * @throws RemoteException
     */
    boolean isCellEditable(int rowIndex, int columnIndex)
            throws RemoteException;

    /**
     * Returns a value for the cell at <tt>rowIndex</tt> and
     * <tt>columnIndex</tt>.
     * 
     * @param rowIndex the row whose value is to be looked up
     * @param columnIndex the column whose value is to be looked up
     * @return the value Object at the specified cell
     * @throws RemoteException
     */
    Object getValueAt(int rowIndex, int columnIndex) throws RemoteException;

    /**
     * Returns the values for all the cells in the table.
     * 
     * @throws RemoteException
     */
    Object getValues() throws RemoteException;

    /**
     * Returns the values for the cells from (firstRow, column) to
     * (lastRow, column). When <tt>column</tt> is
     * {@link RemoteTableModelEvent#ALL_COLUMNS ALL_COLUMNS}, all cells
     * in the specified range of rows are returned.
     * 
     * @throws RemoteException
     */
    Object getValues(int firstRow, int lastRow, int column)
            throws RemoteException;

    /**
     * Assigns a value to the cell at <tt>rowIndex</tt>
     * and <tt>columnIndex</tt>.
     * 
     * @param aValue the new value
     * @param rowIndex the row whose value is to be changed
     * @param columnIndex the column whose value is to be changed
     * @throws RemoteException
     */
    void setValueAt(Object aValue, int rowIndex, int columnIndex)
            throws RemoteException;

    /**
     * Sets the attribute values for the cells from (firstRow, column) to
     * (lastRow, column). When <tt>column</tt> is
     * {@link RemoteTableModelEvent#ALL_COLUMNS ALL_COLUMNS}, all cells
     * in the specified range of rows are set.
     * 
     * @throws RemoteException
     */
    void setValues(Object data, int firstRow, int lastRow, int column)
            throws RemoteException;

    /**
     * Adds a listener to the list that is notified each
     * time a change to the data model occurs.
     * <p>
     * To jump-start the new client, a full update event is
     * sent to the listener just before adding the listener
     * to the list.
     * 
     * @param l the RemoteTableModelListener
     * @throws RemoteException
     */
    void addRemoteTableModelListener(RemoteTableModelListener l)
            throws RemoteException;

    /**
     * Removes a listener from the list that is notified
     * each time a change to the data model occurs.
     * 
     * @param l the RemoteTableModelListener
     * @throws RemoteException
     */
    void removeRemoteTableModelListener(RemoteTableModelListener l)
            throws RemoteException;
}
